home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / pmode / 386p_099 / pcx.asm < prev    next >
Encoding:
Assembly Source File  |  1994-05-02  |  4.4 KB  |  194 lines

  1. ; modulo per la visualizzazione di bitmap Pcx 320x200
  2. ; a 256 colori
  3. .386P
  4.  
  5. code32 segment para public use32
  6.        assume cs:code32,ds:code32
  7.        
  8. include 386power.inc
  9. include 386video.inc
  10. include 386file.inc
  11. include palette.inc
  12.  
  13.         public _Pcx2Scr
  14.         public _PcxDecoded,_PcxHasPalette
  15.         public _PcxLoad        
  16.         align byte
  17. ; Palette extracted from last Pcx file read       
  18. PicPal        db 768 dup(0)
  19.  
  20. _PcxDecoded    db 0
  21. _PcxHasPalette db 0
  22.  
  23. Pcx_len   dd 0
  24. Pcx_start dd 0
  25. Pcx_buf   dd 80 dup(0)
  26.  
  27. _Pcx2Scr:
  28.         ; esi = Pcx data buffer base for a 320x200 Pcx image
  29.         ; eax = Pcx file lenght
  30.         ; expands the 320x200 Pcx image to _ActivePage
  31.         ; starting from coordinates (0,0) to (319,181)
  32.         ; [ Yeah! it cuts it to 320x182 !!!]
  33.         ; remeber to set _DisplayStart to (0,0) before calling this
  34.         pushad
  35.         
  36.         mov Pcx_len,eax
  37.         mov Pcx_start,esi
  38.         mov _PcxDecoded,0    ; still have to decode it
  39.         mov _PcxHasPalette,0 ; still have to read palette
  40.         cmp dword ptr [esi],0801050Ah ; 8 bit/pix, RLE, Ver. 5, Pcx ???
  41.         jne Pcx_err  ; no, get out!
  42.         cmp byte ptr [esi+ 65],01     ; one plane ?
  43.         jne Pcx_err  ; no, get out!
  44.         
  45.         movzx eax,word ptr [esi+66] ; bytes * scanline
  46.         cmp eax,320
  47.         jne Pcx_err ; image too big
  48.         
  49.         movsx eax, word ptr [esi+10] ; ymax
  50.         movsx ebx, word ptr [esi+6 ] ; ymin
  51.         sub eax,ebx
  52.         inc eax
  53.         cmp eax,200
  54.         jne Pcx_err
  55.         
  56.         xor ecx,ecx
  57.         add esi,128  ; go to Pcx data block
  58.         mov edx,0
  59. @yPcx:  mov edi,offset Pcx_buf
  60.         mov eax,0
  61. @xPcx:
  62.         mov bl,[esi]
  63.         mov cl,bl
  64.         inc esi
  65.         cmp bl,0C0h   ; last 64 colors ?
  66.         jnb @Pcxburst ; then this is a RLE burst
  67.         ; else it is a single byte
  68.         mov [edi],cl
  69.         inc eax
  70.         inc edi
  71.         cmp eax,320
  72.         jb @xPcx
  73.         jmp @linne
  74.                 
  75. @Pcxburst:
  76.         mov cl,[esi]
  77.         and ebx,03Fh    ; get count value
  78.         inc esi
  79.         add ebx,eax     ; x value to stop at
  80. buurst: mov [edi],cl
  81.         inc eax
  82.         inc edi
  83.         cmp eax,ebx
  84.         jb buurst
  85.         cmp eax,320
  86.         jb @xPcx
  87. @linne: ; new line of Pcx file
  88.  
  89.         pushad
  90.         ; blit the line buffered into Pcx_buf
  91.         ; edx =  y in pixels
  92.         mov ebx,_ActiveBase
  93.         mov ebp,offset Pcx_buf
  94.         add ebx,[edx*4+_RowStart]
  95.         BLITMODE BLITPLANE
  96.         mov ax,WP0
  97.         mov cl,bl
  98.         mov dx,SEQUENCER
  99.         
  100.         out dx,ax
  101.         mov esi,ebp
  102.         mov edi,ebx
  103.         mov ecx,80
  104. pcx0:
  105.         lodsd
  106.         stosb
  107.         loop pcx0
  108.         
  109.         mov ax,WP1
  110.         out dx,ax
  111.         mov esi,ebp
  112.         mov edi,ebx
  113.         mov ecx,80
  114. pcx1:
  115.         lodsd
  116.         mov al,ah
  117.         stosb
  118.         loop pcx1
  119.         
  120.         mov ax,WP2
  121.         out dx,ax        
  122.         mov esi,ebp
  123.         mov edi,ebx
  124.         mov ecx,80
  125. pcx2:
  126.         lodsd
  127.         shr eax,16
  128.         stosb
  129.         loop pcx2
  130.         
  131.         mov ax,WP3
  132.         out dx,ax
  133.         mov esi,ebp
  134.         mov edi,ebx
  135.         mov ecx,80
  136. pcx3:
  137.         lodsd
  138.         rol eax,8
  139.         stosb
  140.         loop pcx3
  141.         
  142.         popad
  143.         ; now go to next line
  144.         
  145.         inc edx
  146.         cmp edx,182
  147.         jb @yPcx
  148.         
  149.         ; now look for palette data and extract it
  150.         mov esi,Pcx_start
  151.         add esi,Pcx_len
  152.         sub esi,769
  153.         cmp byte ptr [esi],12
  154.         jne @paldone
  155.         mov _PcxHasPalette,1
  156.         inc esi
  157.         mov edi,offset PicPal
  158.         mov ecx,192
  159.   pcx2vgapal:    
  160.         lodsd
  161.         and eax,0FCFCFCFCh ; "cut" the lower bits
  162.         shr eax,2
  163.         stosd
  164.         loop pcx2vgapal
  165.         mov esi, offset PicPal
  166.         call _Set256Palette
  167. @paldone:
  168.         ; Pcx file fully decode
  169.         mov _PcxDecoded,1      
  170. Pcx_err:
  171.         popad
  172.         ret
  173.                 
  174. _PcxLoad: ; DS:ESI == ASCIIZ name of Pcx file to load
  175.           ;
  176.           pushad
  177.           call _FLoad
  178.           jc loaderr
  179.           push eax
  180.           mov eax,0
  181.           mov edx,0
  182.           call _DisplayStart
  183.           call _PageFlip
  184.           pop eax
  185.           mov esi,_HiMemBase
  186.           call _Pcx2Scr
  187.    loaderr:       
  188.           popad
  189.           ret
  190.           
  191. code32 ends
  192.  
  193.  END
  194.